package org.jsbd.boss.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.dao.IEmailGroupDao;
import org.jsbd.boss.domian.EmailGroupBean;
import org.jsbd.boss.domian.EmailGroupRef;
import org.springframework.stereotype.Repository;

import edu.hziee.common.dbroute.BaseDAO;

@Repository("emailGroupDao")
public class EmailGroupDaoImpl extends BaseDAO implements IEmailGroupDao {

	@Override
	public void saveEmailGroup(EmailGroupBean emailGroup) {
		super.insert("qy_channel_email_group.insert_email_group", emailGroup);
	}

	@Override
	public void updateEmailGroup(EmailGroupBean emailGroup) {
		super.insert("qy_channel_email_group.update_email_group", emailGroup);
	}

	@Override
	public EmailGroupBean getEmailGroup(EmailGroupBean emailGroup) {
		return (EmailGroupBean) super.queryForObject("qy_channel_email_group.select_email_group_one", emailGroup);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<EmailGroupBean> getEmailGroupList(EmailGroupBean emailGroup) {
		return super.queryForList("qy_channel_email_group.select_email_group_list", emailGroup);
	}

	@Override
	public Map<String, Object> getEmailGroupListPage(DataGridModel page, EmailGroupBean form) {
		form = (form == null ? new EmailGroupBean() : form);
		form.setPageInfo(page);
		Map<String, Object> results = new HashMap<String, Object>();
		results.put("total", super.queryForCount("qy_channel_email_group.select_email_group_page_count", form));
		results.put("rows", super.queryForList("qy_channel_email_group.select_email_group_list", form));
		return results;
	}

	@Override
	public Integer getEmailGroupCount(EmailGroupBean emailGroup) {
		return super.queryForCount("qy_channel_email_group.select_email_group_page_count", emailGroup);
	}

	public void deleteEmailGroup(EmailGroupBean emailGroup){
		super.delete("qy_channel_email_group.del_email_group", emailGroup);
		super.delete("qy_channel_email_group.del_email_group_ref", emailGroup.getId());
	}
	
	@Override
	public Map<String, Object> getOutEmailListPage(DataGridModel page, EmailGroupRef form) {
		form = (form == null ? new EmailGroupRef() : form);
		form.setPageInfo(page);
		Map<String, Object> results = new HashMap<String, Object>();
		results.put("total", super.queryForCount("qy_channel_email_group.getOutEmailListPageCount", form));
		results.put("rows", super.queryForList("qy_channel_email_group.getOutEmailListPage", form));
		return results;
	}

	@Override
	public Map<String, Object> getInEmailListPage(DataGridModel page, EmailGroupRef form) {
		form = (form == null ? new EmailGroupRef() : form);
		form.setPageInfo(page);
		Map<String, Object> results = new HashMap<String, Object>();
		results.put("total", super.queryForCount("qy_channel_email_group.getInEmailListPageCount", form));
		results.put("rows", super.queryForList("qy_channel_email_group.getInEmailListPage", form));
		return results;
	}

	@Override
	public void saveEmailGroupRef(EmailGroupRef emailGroupRef) {
		super.insert("qy_channel_email_group.save_email_group_ref", emailGroupRef);
	}
	
	@Override
	public void deleteEmailGroupRef(EmailGroupRef emailGroupRef) {
		super.delete("qy_channel_email_group.delete_email_email_group_ref", emailGroupRef);
	}

	@Override
	public void saveEmailGroupRef(List<EmailGroupRef> emailGroupRef) {
		super.batchInsert("qy_channel_email_group.save_email_group_ref", emailGroupRef);
	}

	/* (non-Javadoc)
	 * @see org.webunion.monitor.dao.IEmailGroupDao#deleteEmailGroupRef(java.util.List)
	 */
	@Override
	public void deleteEmailGroupRef(List<EmailGroupRef> emailGroupRef) {
		super.batchUpdate("qy_channel_email_group.delete_email_email_group_ref", emailGroupRef);
	}
	
	
}
